package org.scep.model;

import java.io.IOException;

public class ServerFileHandle
{

	protected long startPos; // File Start Position
	protected FileAccess fileAccess = null; // File Access interface
	private int id;
	private String stamp;

	public ServerFileHandle(String filePath, long start, int id) throws IOException
	{
		this.startPos = start;
		this.id = id;
		fileAccess = new FileAccess(filePath, startPos);
	}

	public void write(byte[] b,int length,String timestamp) throws IOException
	{
		if(stamp != null && stamp.equals(timestamp)){
			System.out.println(id + ":reSend");
			return;
		}
//		System.out.println(id + ":" + length);
		startPos += fileAccess.write(b, 0, length);
		stamp = timestamp;
	}

	public void close() throws IOException{
		if(fileAccess != null){
			fileAccess.close();
		}
	}
	
	public int getID(){
		return id;
	}
}
